package com.gdpu.project.dao.impl;

import java.util.Date;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.gdpu.project.dao.ProApplyDao;
import com.gdpu.project.vo.ProApply;

/**
 * A data access object (DAO) providing persistence and search support for
 * ProApply entities. Transaction control of the save(), update() and delete()
 * operations can directly support Spring container-managed transactions or they
 * can be augmented to handle user-managed Spring transactions. Each of these
 * methods provides additional information for how to configure it for the
 * desired type of transaction control.
 * 
 * @see com.gdpu.project.vo.ProApply
 * @author MyEclipse Persistence Tools
 */

public class ProApplyDaoImpl extends HibernateDaoSupport implements ProApplyDao {
	private static final Log log = LogFactory.getLog(ProApplyDaoImpl.class);
	// property constants
	public static final String PROJECT_ID = "projectId";
	public static final String TEACHER_ID = "teacherId";
	public static final String APPLY_STATE = "applyState";

	protected void initDao() {
		// do nothing
	}

	/* (non-Javadoc)
	 * @see com.gdpu.project.dao.impl.ProApplyDao#save(com.gdpu.project.vo.ProApply)
	 */
	public void save(ProApply transientInstance) {
		log.debug("saving ProApply instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.gdpu.project.dao.impl.ProApplyDao#delete(com.gdpu.project.vo.ProApply)
	 */
	public void delete(ProApply persistentInstance) {
		log.debug("deleting ProApply instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.gdpu.project.dao.impl.ProApplyDao#findById(java.lang.Integer)
	 */
	public ProApply findById(java.lang.Integer id) {
		log.debug("getting ProApply instance with id: " + id);
		try {
			ProApply instance = (ProApply) getHibernateTemplate().get(
					"com.gdpu.project.vo.ProApply", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.gdpu.project.dao.impl.ProApplyDao#findByExample(com.gdpu.project.vo.ProApply)
	 */
	public List<ProApply> findByExample(ProApply instance) {
		log.debug("finding ProApply instance by example");
		try {
			List<ProApply> results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.gdpu.project.dao.impl.ProApplyDao#findByProperty(java.lang.String, java.lang.Object)
	 */
	public List<ProApply> findByProperty(String propertyName, Object value) {
		log.debug("finding ProApply instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from ProApply as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.gdpu.project.dao.impl.ProApplyDao#findByProjectId(java.lang.Object)
	 */
	public List<ProApply> findByProjectId(Object projectId) {
		return findByProperty(PROJECT_ID, projectId);
	}

	/* (non-Javadoc)
	 * @see com.gdpu.project.dao.impl.ProApplyDao#findByTeacherId(java.lang.Object)
	 */
	public List<ProApply> findByTeacherId(Object teacherId) {
		return findByProperty(TEACHER_ID, teacherId);
	}

	/* (non-Javadoc)
	 * @see com.gdpu.project.dao.impl.ProApplyDao#findByApplyState(java.lang.Object)
	 */
	public List<ProApply> findByApplyState(Object applyState) {
		return findByProperty(APPLY_STATE, applyState);
	}

	/* (non-Javadoc)
	 * @see com.gdpu.project.dao.impl.ProApplyDao#findAll()
	 */
	public List<ProApply> findAll() {
		log.debug("finding all ProApply instances");
		try {
			String queryString = "from ProApply";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.gdpu.project.dao.impl.ProApplyDao#merge(com.gdpu.project.vo.ProApply)
	 */
	public ProApply merge(ProApply detachedInstance) {
		log.debug("merging ProApply instance");
		try {
			ProApply result = (ProApply) getHibernateTemplate().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.gdpu.project.dao.impl.ProApplyDao#attachDirty(com.gdpu.project.vo.ProApply)
	 */
	public void attachDirty(ProApply instance) {
		log.debug("attaching dirty ProApply instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.gdpu.project.dao.impl.ProApplyDao#attachClean(com.gdpu.project.vo.ProApply)
	 */
	public void attachClean(ProApply instance) {
		log.debug("attaching clean ProApply instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static ProApplyDao getFromApplicationContext(ApplicationContext ctx) {
		return (ProApplyDao) ctx.getBean("ProApplyDAO");
	}
}